<?php
    // array for JSON response
    $response = array();

    
    // get all sub comment from sub_comment table
    if(isset($_GET['comment_id'])){
	    // include db connect class
		require_once __DIR__ . '/db_connect.php';
		// connecting to db
		$db = new DB_CONNECT();
		$stt = 1;
        if(isset($_GET['loadMore'])){
            $result = mysql_query("SELECT sub_comment.description, sub_comment.time_sub_comment, sub_comment.id, user.user_id, user.user_id_zing, user_display_name, user.user_avatar_zing "
				."FROM sub_comment, user WHERE sub_comment.comment_id =".$_GET['comment_id']." and user.user_id_zing=sub_comment.user_id_zing"
				." ORDER BY sub_comment.time_sub_comment DESC ") or die(mysql_error());
        }else{
            $result = mysql_query("SELECT sub_comment.description, sub_comment.time_sub_comment, sub_comment.id, user.user_id, user.user_id_zing, user.user_display_name, user.user_avatar_zing "
				."FROM sub_comment, user WHERE sub_comment.comment_id =".$_GET['comment_id']." and user.user_id_zing=sub_comment.user_id_zing"
				." ORDER BY sub_comment.time_sub_comment DESC LIMIT 3") or die(mysql_error());
        }
               
        if (mysql_num_rows($result) > 0) {
                $response["subcomment"] = array();
                while ($row = mysql_fetch_array($result)) {
                        $subcomment = array(); 
						$subcomment['description'] = $row['description'];
                        $subcomment['time_sub_comment'] = $row['time_sub_comment'];
                        $subcomment['sub_commment_id'] = $row['id'];
                        $subcomment['user_id'] = $row['user_id'];
                        $subcomment['user_id_zing'] = $row['user_id_zing'];
                        $subcomment['user_display_zing'] = $row['user_display_name'];
                        $subcomment['user_avatar_zing'] = $row['user_avatar_zing'];
                        $subcomment['stt'] = $stt;
                        $stt++;
                        // push single product into final response array
                        array_push($response['subcomment'],$subcomment);
                }
                // success
            $response["success"] = 1;
                echo json_encode($response);
        }
        else{
            $response["subcomment"] = "No sub comment";
            $response["success"] = 1;
                echo json_encode($response);
        }
    }else{
		$response["subcomment"] = "Error _GET";
        $response["success"] = 0;
        echo json_encode($response);
	}
?>

